package cn.dengta.webapp.im.vo;

import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.annotation.Nullable;

import cn.dengta.context.model.Language;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.im.dto.ImIntegralDTO;
import cn.dengta.webapp.im.entity.GreetText;
import cn.dengta.webapp.user.model.Gender;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.X;

@Getter
@Setter
public class GreetTextVO extends AbstractVO<GreetText> {

	/** 性别:0=女;1=男 */
	private Integer gender;
	/** 招呼内容 */
	private String content;
	/** 语言 */
	private Language language;
	/** tip提示 */
	private Object tips;

	/**
	 * 类型：0=搭讪；1=快捷回复; 2=搭讪
	 *
	 * @see GreetText.GreetTextType
	 */
	private Integer textType;

	private Integer useCount;
	private Integer replyCount;
	/** 牵线、搭讪 TIP 消息 */
	private String pullTip;

	/**
	 * 用于后台页面多语言展示
	 */
	public static GreetTextVO from(@Nullable GreetText source) {
		GreetTextVO vo = copy(source, GreetTextVO::new);
		if (source.getType() != null) {
			vo.setTextType(source.getType().value);
		}
		return vo;
	}

	public String getGender_() {
		return X.map(Gender.of(gender), Gender::getLabel);
	}

	public Integer getLanguage() {
		return X.map(language, Language::getValue);
	}

	public String getLanguage_() {
		return X.map(language, Language::getLabel);
	}

	public static String getReplyRate(Integer useCount, Integer replyCount) {

		useCount = X.expectNotNull(useCount, 0);
		replyCount = X.expectNotNull(replyCount, 0);
		BigDecimal replyRate = BigDecimal.ZERO;
		if (useCount > 0 && replyCount > 0) {
			BigDecimal useCountB = BigDecimal.valueOf(useCount, 4);
			BigDecimal replyCountB = BigDecimal.valueOf(replyCount, 4);
			replyRate = replyCountB.divide(useCountB, RoundingMode.HALF_DOWN).multiply(BigDecimal.valueOf(100));
		}
		return replyRate.setScale(2, RoundingMode.HALF_DOWN).toString() + "%";
	}

	public String getReplyRate() {
		return getReplyRate(useCount, replyCount);
	}

}
